Cartridge genotype plane: persist population genotype priors on a cartridge - #7
Merged
Conversation
…normalizer, allow_nonfunctional bool)
…py carried novels
…ne subject check, order-independent draws
… round) - from_genotypes: validate pseudocount (finite >=0, reject bool); reject unknown carried alleles; reject copy_count>1 single-entry slots; validate model before return - Genotype.sample: validate a directly-attached plane before use - manifest: report genotype_priors 'valid' flag, never leak NaN numerics - to_metadata: add effective_refdata_hash for carried-novel genotypes
…nd 2) - manifest: never crash on a garbage/invalid direct-attached plane (type-check, guard content_checksum/float, defensive dict access) - Genotype.sample: require use_cartridge_priors to be a real bool - from_genotypes: require include_novel bool; validate min_subjects (int>=1) and segments (non-empty unique V/D/J labels present in cfg; reject bare string)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds a donor-population germline prior ("population genotype model") as a top-level cartridge plane (
DataConfig.genotype_priors), soGenotype.sample(cfg)can draw per-individual genotypes from a cartridge-authored prior instead of a uniform synthetic one. Follow-on #2 of the genotype roadmap (after V1 #5 and population priors #6).Python-only — zero
engine_rs/changes. The plane is consumed entirely inGenotype.sample, which already lowers a fully-specified genotype through the existingSampleGenotypePass; population novel alleles reuse the existing effective-refdata injection. NoExperimentAPI change.What's included
genotype_priors.py—PopulationGenotypeModel+PopulationNovelAllele: per-segment/gene allele frequencies, per-gene haplotype-deletion probabilities, chromosome weights, population novel alleles, and identity (model_id/source/version/description). Catalogue-freevalidate()(shape, numeric bounds, DNA, ChainType-normalized D-on-VJ rejection) + canonicalcontent_checksum().PopulationGenotypeModel.from_genotypes(...)— pure estimator from observedGenotypes: per-chromosome allele counts (homozygous=2 / hemizygous=1), deletion prob =deleted_haplotypes / (2·n_subjects), pseudocount on catalogue alleles only, with completeness / copy-number / subject-id / input-type guards.DataConfig.genotype_priors— fifth top-level plane; legacy-pickle fallback; None-pop checksum shim (unused plane → byte-identical cartridge checksum; a real plane → distinct identity);models.genotype_priorsmanifest block (robust against malformed direct-attached planes).Genotype.sample— per-input source resolution withuse_cartridge_priorsopt-out; candidate-vs-carried novel injection (include_cartridge_novel_alleles); genotype-levelprior_provenance+to_metadata()(base + effective refdata hashes); order-independent draws.set_genotype_priors(catalogue-aware + functional novel validation) and chainableestimate_genotype_priors.Invariants
compute_checksum(); a real plane is part of cartridge identity.effective_dataconfig()/ AIRR projection — uncarried candidates never leak.Test plan
tests/test_genotype_cartridge_plane.py(45 tests): validation, checksum invariant + canonicality, serialization round-trip, manifest, sampler provenance/opt-out/mixed-sourcing, candidate-vs-carried novel injection, estimator statistics + guards, builder set/estimate, input-type hardening, end-to-end truth-call carriage.engine_rs/changes (compiled engine byte-identical).